$include("$theme/coverFlowView.css");

$import("lib.jquery-roundabout");

with ($ns("qp.controls"))
{
    qp.controls.CoverFlowView = function($p_container, p_options)
    {
        var me = new mx.controls.JQControl($p_container, p_options);
        var base = {};
        
        me.entries = null;
        me.selection = null;
        
        me.onselectionchanged = null;
        
        me.init = function()
        {
            me.$container.addClass("coverFlowView");
        };
        
        me.loadEntries = function(p_entries)
        {
            me.entries = p_entries;
            if (me.entries.length > 0)
            {
                me.selection = me.entries[0];
            }
            else
            {
                me.selection = null;
            }
            me.trigger("selectionchanged");

            me.$("li").remove();
            for (var i = 0; i < me.entries.length; i++)
            {
                var $li = $("<li/>");
                var entry = me.entries[i];
                var imgUrl = entry.link.image.replace("spic", "lpic");
                
                var title = null;
                if (entry.title_cn)
                {
                    title = entry.title_cn + " " + entry.title;
                }
                else
                {
                    title = entry.title;
                }
                
                $li.attr("title", title);
                $li.css("backgroundImage", "url(" + imgUrl + ")");
                $li.data("entry", entry);
                me.$container.append($li);
            }
            me.$container.roundabout({
                minOpacity: 0.3
            });
            me.$container.find("li").click(_li_onclick);
        };
        
        
        function _li_onclick(e)
        {
            var entry = $(e.target).data("entry");
            me.selection = entry;
            me.trigger("selectionchanged");
        }
        
        return me;
    }
}